package com.inspur.demo.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 *    
 * 控制层
 *
 * @desc:
 * @author: li.peng02
 * @date: 2019/3/14
 * @version: v1.0 
 */
@RestController
public class RibbonController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private LoadBalancerClient loadBalancerClient;

    @RequestMapping("/ribbon/test")
    public void test01() {
        ServiceInstance choose = loadBalancerClient.choose("spring-cloud-producer");
        logger.info(choose.getHost() + ":" + choose.getPort());
    }
}
